﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Oracle.DataAccess.Client;

namespace Sweepids.Models.Object
{
    public class CreditCard
    {
        //Columns
        public string CardNum { get; set; }
        public DateTime ExpDate { get; set; }
        public string SecCode { get; set; }
        //Foreign keys
        //Oracle parameters
        public List<OracleParameter> OracleParameters
        {
            get
            {
                return new List<OracleParameter>
                    {
                        new OracleParameter(":CARD_NUM", OracleDbType.Varchar2)
                            {
                                Value = CardNum ?? ""
                            },
                        new OracleParameter(":EXP_DATE", OracleDbType.Date)
                            {
                                Value = ExpDate
                            },
                        new OracleParameter(":SEC_CODE", OracleDbType.Varchar2)
                            {
                                Value = SecCode ?? ""
                            }
                    };
            }
        }
        //Constructors
        public CreditCard()
        {
            CardNum = "";
            SecCode = "";
        }
        public CreditCard(IDataRecord myReader)
        {
            CardNum = myReader["CARD_NUM"] == DBNull.Value ? "" : (string) myReader["CARD_NUM"];
            ExpDate = myReader["EXP_DATE"] == DBNull.Value ? DateTime.Now : (DateTime) myReader["EXP_DATE"];
            SecCode = myReader["SEC_CODE"] == DBNull.Value ? "" : (string) myReader["SEC_CODE"];
        }
    }
}